import json
from os import stat
from django.views import View
from django.http import JsonResponse

from rbac.models import Roles,Department

from rbac.utils import *;


# 所有部门数据列表
class Depart(View):
    def get(self, request):

        query = request.GET

        name = query.get("name")
        status = query.get("status")

        department = Department.objects
        # 名字搜索
        if(name):
            department = department.filter(name__contains=name)

        if(status):
            department = department.filter(status = status)

        department = department.values()

        departTree = getTree(list(department))

        return JsonResponse({
            'code': 200,
            'data': departTree,
            'msg': "获取部门列表数据",
        })
